<?php
class categoryController extends siteController
{
    public function index()
    {

        $cid = intval($_GET['cid']);
        $urlname = in($_GET['urlname']);
        if (empty($cid)&&empty($urlname)) {
            $this->error404();
        }
        if(!empty($cid)){
            $this->info=model('category_list')->info($cid);
        }else if(!empty($urlname)){
            $this->info=model('category_list')->info($urlname,true);
        }else{
            $this->error404();
        }
        
        if (!is_array($this->info)){
            $this->error404();
        }
        if($this->info['model']<>APP_NAME){
            $this->error404();
        }
        //位置导航
        $this->nav=api('default','category_nav',$this->info['cid']);

        //设置分页
        $size = intval($this->info['page']); 
        if (empty($size)) {
            $listrows = 10;
        } else {
            $listrows = $size;
        }
        $url=model('label_category')->get_curl($this->info,true);
        $limit=$this->pageLimit($url,$listrows);
        $where='';
        //设置栏目属性
        if ($this->info['type'] == 0) {
            $son_id = api('default','category_getcat',$this->info['cid']);
            $where .= 'A.status=1 AND B.cid in (' . $son_id . ')';
        } else {
            $where .= 'A.status=1 AND B.cid=' . $this->info['cid'];
        }

        //条件接口
        $where_list=ApiHook('hook_category_list_where',array('info'=>$this->info,'app'=>APP_NAME));
        if(!empty($where_list)){
            foreach ($where_list as $value) {
                $where.=$value;
            }
        }

        //执行查询列表
        $loop=model('category_list')->content_list($this->info,$where,$limit,$this->info['content_order']);
        $count = model('category_list')->content_count($this->info,$where);
        if(!empty($loop)){
            $i=0;
            foreach ($loop as $key=>$value) {
                $i++;
                $list[$key]=$value;
                $list[$key]['aurl']=model('label_content')->get_aurl($value);
                $list[$key]['i']=$i;
            }
        }
        $this->loop=$list;
        //获取分页
        $this->page=$this->pageShow($count);
        $this->count=$count;
        //查询上级栏目信息
        $this->parent_category = model('category_list')->info($this->info['pid']);
        //获取顶级栏目信息
        $this->top_category = model('category_list')->info($this->nav[0]['cid']);
        //MEDIA信息
        $this->common=api('default','common_media',array('title'=>$this->info['name'],'keywords'=>$this->info['keywords'],'description'=>$this->info['description']));
        

        //赋值接口
        $assign_list=ApiHook('hook_category_assign',array('info'=>$this->info,'app'=>APP_NAME));
        if(!empty($assign_list)){
            foreach ($assign_list as $value) {
                $this->view()->assign($value);
            }
        }
        

        $this->show($this->info['class_tpl']);
    }

}
